package cn.t.constants.device;


import cn.t.core.enums.base.CommonEnum;
import cn.t.core.enums.base.CommonError;
import cn.t.core.exception.BizException;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author l
 */

@Getter
@AllArgsConstructor
public enum HeartbeatTypeEnum implements CommonEnum<Integer, String> {

    HTTP(1, "http"), MQTT(2, "mqtt");
    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;

    public static HeartbeatTypeEnum getByCode(Integer source) {
        for (HeartbeatTypeEnum value : HeartbeatTypeEnum.values()) {
            if (value.code.equals(source)) {
                return value;
            }
        }

        throw new BizException(CommonError.ILLEGAL_PARAMETER);
    }
}